package com.zxt.web.database.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * 自动填充字段
 */
public class ContentMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        LocalDateTime now = LocalDateTime.now();
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, now);
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, now);
        /*HttpServletRequest request = ServletUtil.getRequest();
        BUserInfoApiVO user = UserUtil.getUser(request);
        if (Objects.isNull(user)) {
            return;
        }
        this.strictInsertFill(metaObject, "createBy", String.class, user.getNickName());
        this.strictInsertFill(metaObject, "storeId", Long.class, user.getStoreId());*/

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        /*HttpServletRequest request = ServletUtil.getRequest();
        BUserInfoApiVO user = UserUtil.getUser(request);
        if (Objects.isNull(user)) {
            return;
        }
        this.strictUpdateFill(metaObject, "updateBy", String.class, user.getNickName());*/
    }

}